/**
 * @author  guocailee
 */

export default {
  setItem(key, data) {
    if (!window.localStorage || !window.JSON || !key) {
      return
    }
    window.localStorage.setItem(key, JSON.stringify(data))
  },
  getItem(key) {
    if (!window.localStorage || !window.JSON || !key) {
      return
    }
    let item = window.localStorage.getItem(key)
    if (!item) {
      return
    }
    return JSON.parse(item)
  },
  removeItem(key) {
    if (!window.localStorage || !window.JSON || !key) {
      return
    }
    window.localStorage.removeItem(key)
  },
  available: !!window.localStorage
}
